package com.yanyu.space.sys.controller;


import com.yanyu.space.common.core.bean.db.PageEntity;
import com.yanyu.space.common.core.bean.web.R;
import com.yanyu.space.sys.bean.po.Post;
import com.yanyu.space.sys.bean.vo.post.PostSearchVo;
import com.yanyu.space.sys.service.IPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 职位 前端控制器
 *
 * @author yanyu
 */
@RestController
@RequestMapping("/sys/post")
@Api(tags = "职位")
@AllArgsConstructor
@Validated
public class PostController {

    private IPostService postService;

    @GetMapping("/list")
    @ApiOperation(value = "查询岗位")
    public R<PageEntity<Post>> list(PostSearchVo vo) {
        PageEntity<Post> page = postService.listPage(vo);
        return R.ok(page);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询岗位")
    public R<Post> get(@PathVariable(value = "id") Long id) {
        return R.ok(postService.getById(id));
    }

    @PostMapping
    @ApiOperation(value = "新增岗位")
    public R add(@RequestBody Post vo) {
        postService.save(vo);
        return R.ok();
    }

    @PutMapping
    @ApiOperation(value = "修改岗位")
    public R update(@RequestBody Post vo) {
        postService.updateById(vo);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "修改岗位")
    public R update(@PathVariable("id") Long id) {
        postService.removeById(id);
        return R.ok();
    }

}

